//
//  NSString+time.m
//  聚超值
//
//  Created by 周abel on 16/4/1.
//  Copyright © 2016年 Zhli. All rights reserved.
//

#import "NSString+time.h"

@implementation NSString (time)

// 获取时间(时,分)
+ (NSString *)getTime:(NSNumber *)number {
    
    // 转换成时间
    long long int dataNow = [number longLongValue];

    NSDate *date = [NSDate dateWithTimeIntervalSince1970:dataNow/1000];
    
    NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
    
    // 格式化
    formatter.dateFormat = @"MM-dd-HH:mm zh";
    
    NSString *res = [formatter stringFromDate:date];
    
    // 计算时间差
    NSTimeInterval timeInterval = [date timeIntervalSinceNow];
    
    timeInterval = -timeInterval;
    
    long int temp = 0;
    
    NSString *result = nil;
    
    if (timeInterval < 60) {
         result = [NSString stringWithFormat:@"刚刚"];
    }
    else if((temp = timeInterval/60) <60){
        
        // 多少分钟前
        result = [NSString stringWithFormat:@"%ld分前",temp];
        
    } else if((temp = temp/60) <24){
        
        // 时间(一天之内)
        NSRange range = NSMakeRange(6, 5);
        
        result = [res substringWithRange:range];
        
    } else {
        // 日期(超过一天)
        result = [res substringToIndex:5];
    }

    return result;
}
@end
